package com.polaris.live.adapter.live

import android.text.TextUtils
import android.view.View
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.common.ext.autoDp
import com.polaris.live.common.ext.dp
import com.polaris.live.databinding.AdapterHomeLiveItemBinding
import com.polaris.live.resp.back_resp.DisplayUserBean
import com.polaris.live.utils.image.loadWejoyImage
import com.polaris.live.widget.LevelView

/**
 * HomeFollowRecommendAdapter
 *
 * @author Created by 天晴 on 2024/3/5/005 11:41
 */
class HomeFollowRecommendAdapter : BaseBindingAdapter<AdapterHomeLiveItemBinding, DisplayUserBean>() {

    override fun convert(
        holder: VBViewHolder<AdapterHomeLiveItemBinding>,
        item: DisplayUserBean,
    ) {
        holder.vb.apply {
            Glide.with(root.context)
                .loadWejoyImage(item.cover)
                .transform(CenterCrop(), RoundedCorners(8.dp))
                .into(userCover)

            nickName.text = item.base.nickname

            widgetState.setState(item.base, item)

            if (TextUtils.isEmpty(item.base.country)) {
                userCountry.visibility = View.GONE
            } else {
                userCountry.visibility = View.VISIBLE
                userCountry.setCountry(item.base.country)
            }
            widgetSubscript.setUserSymbol(item.symbol)
            levelView.setRichCharmBySexLevel(
                item.base.sex,
                item.base.richs,
                item.base.charms,
                LevelView.LEVEL_VIEW_SMALL
            )
            vipView.setVipLevel(item.base.vipLevel, 45.autoDp, 14.autoDp)
            tvUserNum.text = item.stayUser.toString()
        }
    }

}